package org.huawei260.TiKu.B;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Auther: qingle
 * @Date: 2024/10/27-22:40
 * @Description:
 * @version: 1.0
 */
public class B_2512_2023B_矩阵稀疏扫描 {
//
//	public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	// 行的数量
	int M = sc.nextInt();
	// 列的数量
	int N = sc.nextInt();
	// 正矩阵（行是行，列是列）
	int[][] rowArr = new int[M][N];
	//通过二维数组接受矩阵信息
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			rowArr[i][j] = sc.nextInt();
		}
	}

	//初始化满足稀疏列的行数
	int rowTimes = 0;
	//初始化满足稀疏行的行数
	int colTime = 0;
	//初始化每行最大连续0的个数
	int maxRowCount = 0;
	//初始化每行连续0的个数
	int rowCount = 1;

	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			if(rowArr[i][j] == 0){
				if(j+1 < N && rowArr[i][j+1] == 0){
					rowCount++;
				}
				maxRowCount = Math.max(rowCount, maxRowCount);
			}else {
				//连续0区间被断开，将rowCount重置为1
				rowCount = 1;
			}
			//列的处理，只需要在遍历第一行数据时，通过深度搜索进行判断
			if (i==0){
				dfs(rowArr, i, j, M, 0);
				if(maxColCount > M/2){
					colTime++;
				}
				//每列遍历结束后，将maxColcount重置为0
				maxColCount = 0;
			}
		}
		if(maxRowCount > N/2){
			rowTimes++;
		}
		//每行遍历结束后，将maxCount，rowCount进行重置
		maxRowCount = 0;
		rowCount = 1;
	}
	System.out.println("稀疏行的个数："+rowTimes);
	System.out.println("稀疏列的个数："+colTime);
}

	static int maxColCount = 0;
	private static void dfs(int[][] rowArr, int i, int j, int m, int count) {
		if(rowArr[i][j] == 0) count++;
		maxColCount = Math.max(maxColCount, count);
		if(i+1 < m){
			if(rowArr[i+1][j] == 1){
				//连续0区间被断开，将count重置为1
				count = 0;
			}
			dfs(rowArr, i+1, j, m, count);
		}
	}

	}